Dart Runes operator ==
Syntax & Examples
Runes.operator == operator
The `==` operator in Dart checks for equality between two objects.
Syntax of Runes.operator ==
The syntax of Runes.operator == operator is:
operator ==(dynamic other) → boolThis operator == operator of Runes the equality operator.
Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
other | required | The object to compare with. |
✐ Examples
1 Comparing runes 'a' and 'a'
In this example,
- We create two Rune objects
rune1andrune2with the same character 'a'. - We use the
==operator to comparerune1andrune2. - We print the result which is
truebecause both runes are equal.
Dart Program
void main() {
Rune rune1 = Rune('a');
Rune rune2 = Rune('a');
bool result = rune1 == rune2;
print(result);
}Output
true
2 Comparing ASCII and character runes
In this example,
- We create two Rune objects
rune1andrune2with the character 'A', one using the ASCII value and the other directly as a character. - We use the
==operator to comparerune1andrune2. - We print the result which is
truebecause both runes are equal.
Dart Program
void main() {
Rune rune1 = Rune(65); // 'A' in ASCII
Rune rune2 = Rune('A');
bool result = rune1 == rune2;
print(result);
}Output
true
3 Comparing different character runes
In this example,
- We create two Rune objects
rune1andrune2with the characters 'a' and 'b' respectively. - We use the
==operator to comparerune1andrune2. - We print the result which is
falsebecause the runes are not equal.
Dart Program
void main() {
Rune rune1 = Rune('a');
Rune rune2 = Rune('b');
bool result = rune1 == rune2;
print(result);
}Output
false
Summary
In this Dart tutorial, we learned about operator == operator of Runes: the syntax and few working examples with output and detailed explanation for each example.